public class ThreadDemo6 {
    private static final long count = 10_0000_0000L;

    public static void serial(){
        // System.currentTimeMillis(); 获取到当前系统的毫秒级时间戳
        long beg = System.currentTimeMillis();
        int a = 0;
        for (long i = 0; i < count; i++) {
            a++;
        }
        int b = 0;
        for (long i = 0; i < count; i++) {
            b++;
        }
        long end = System.currentTimeMillis();
        System.out.println("time: "+(end - beg));
    }

    public static void concurrency() {
        long beg = System.currentTimeMillis();

        Thread t1 = new Thread(){
            @Override
            public void run() {
                int a = 0;
                for (long i = 0; i < count; i++) {
                    a++;
                }
            }
        };
        t1.start();

        Thread t2 = new Thread(){
            @Override
            public void run() {
                int b = 0;
                for (long i = 0; i < count; i++) {
                    b++;
                }
            }
        };
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end = System.currentTimeMillis();
        System.out.println("time: "+(end - beg));
    }

    public static void main(String[] args) {
        serial();
        concurrency();
    }
}
